Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a flag_set out of an integral value #161

Conversation

meikjaeckle
Copy link
Contributor

@meikjaeckle meikjaeckle commented Feb 23, 2024

Implements #160

I extended the flag_set template class by a static method which allows to create the flag_set out of an integral value.

This is helpful for e.g. if you read the flags from a device via serial communication.

e.g.

uint8_t readErrorFromDevice();

enum class ErrorBits
{
    ERROR_BIT_0,
    ERROR_BIT_1,
    ERROR_BIT_2,
    ERROR_BIT_3,
    _flag_set_size,
};

using ErrorStatus = type_safe::flag_set<ErrorBits>;

ErrorStatus status = ErrorStatus::from_int(readErrorFromDevice())

Copy link
Owner

@foonathan foonathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, thank you! Just one comment.

include/type_safe/flag_set.hpp Outdated Show resolved Hide resolved
@meikjaeckle meikjaeckle requested a review from foonathan March 5, 2024 23:48
@saburch
Copy link

saburch commented Apr 4, 2024

Great addition @meikjaeckle. Very helpful change.
@foonathan Would be nice to have it in an official release 😄

@foonathan foonathan merged commit fb5eba9 into foonathan:main Apr 22, 2024
@foonathan
Copy link
Owner

Thanks! And sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants